﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StockRepository.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the StockRepository type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DocProcessingRepository.Repositories
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using DocProcessingRepository.Contexts;
  using DocProcessingRepository.Interfaces;
  using EFRepository;
  using Entities;

  public class StockRepository : BaseEfRepository<Stock>, IStockRepository
  {
    public StockRepository(String connectionString)
      : base(new IdentityDb(connectionString))
    {
    }

    public List<StockEntity> GetStockByType(String stockType, String filter)
    {
      List<StockEntity> stock =
        this.GetEntityListByStoreProcedure<StockEntity>(String.Format("exec GetStockByType '{0}', '{1}'", stockType, filter))
        .ToList();

      return stock;
    }

    public StockEntity CreateStock(
      Int32 stockTypeId,
      String code,
      String description,
      Int32 weight,
      Int32 sizeX,
      Int32 sizeY,
      Char facing,
      String colour)
    {
      String sql = String.Format(
        "CreateStock {0}, '{1}', '{2}', {3}, {4}, {5}, '{6}', '{7}'",
        stockTypeId,
        code,
        description,
        weight,
        sizeX,
        sizeY,
        facing,
        colour);

      StockEntity stock = this.GetEntityListByStoreProcedure<StockEntity>(sql).Single();
      return stock;
    }
  }
}
